home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.11 Nov 95 / ODF Beeper / Sources / BeeperPart.cpp < prev    next >
Encoding:
Text File  |  1995-09-26  |  8.4 KB  |  354 lines  |  [TEXT/MPS ]

  1. //==========================================================
  2. //
  3. //    File:                BeeperPart.cpp
  4. //    Release Version:    $ 1.0d9 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //    Modified by M.Boetcher to accept Dropped and Pasted sounds
  8. //
  9. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //==========================================================
  12.  
  13. #ifndef BEEPERPART_H
  14. #include "BeeperPart.h"
  15. #endif
  16.  
  17. #ifndef BEEPERDEF_H
  18. #include "BeeperDef.h"
  19. #endif
  20.  
  21. #ifndef BEEPERSEL_H
  22. #include "BeeperSel.h"
  23. #endif
  24.  
  25. #ifndef ACTIONS_H
  26. #include "Actions.h"
  27. #endif
  28.  
  29. // ----- Framework Layer -----
  30.  
  31. #ifndef FWPUSHBU_H
  32. #include "FWPushBu.h"
  33. #endif
  34.  
  35. // ----- OS Layer -----
  36.  
  37. #ifndef FWRECSHP_H
  38. #include "FWRecShp.h"
  39. #endif
  40.  
  41. #ifndef FWODGEOM_H
  42. #include "FWODGeom.h"
  43. #endif
  44.  
  45. #ifndef FWMEMMGR_H
  46. #include "FWMemMgr.h"
  47. #endif
  48.  
  49. #ifndef FWMENU_H
  50. #include "FWMenu.h"
  51. #endif
  52.  
  53. #ifndef FWBARRAY_H
  54. #include "FWBArray.h"
  55. #endif
  56.  
  57. // ----- Foundation Layer -----
  58.  
  59. #ifndef FWNOTIFN_H
  60. #include <FWNotifn.h>
  61. #endif
  62.  
  63. #ifndef FWCLAINF_H
  64. #include <FWClaInf.h>
  65. #endif
  66.  
  67. // ----- OpenDoc Includes -----
  68.  
  69. #ifndef _ODTYPES_
  70. #include <ODTypes.h>
  71. #endif
  72.  
  73. #ifndef SOM_Module_OpenDoc_StdProps_defined
  74. #include <StdProps.xh>
  75. #endif
  76.  
  77. #ifndef SOM_ODStorageUnit_xh
  78. #include <StorageU.xh>
  79. #endif
  80.  
  81. #ifndef SOM_ODTranslation_xh
  82. #include <Translt.xh>
  83. #endif
  84.  
  85. #ifndef SOM_ODSession_xh
  86. #include <ODSessn.xh>
  87. #endif
  88.  
  89. #ifndef SOM_ODDragItemIterator_xh
  90. #include <DgItmIt.xh>
  91. #endif
  92.  
  93. // ----- Macintosh Includes -----
  94. #if defined(FW_BUILD_MAC) && !defined(__SOUND__)
  95. #include <Sound.h>
  96. #endif
  97.  
  98.  
  99. //==========================================================
  100. //    Runtime Information
  101. //==========================================================
  102.  
  103. #pragma segment BeeperPart
  104.  
  105. //==========================================================
  106. //    Globals
  107. //==========================================================
  108.  
  109. const ODValueType CBeeperPart::kPartKind = kODFBeeperKind;
  110.  
  111. //==========================================================
  112. //    class CBeeperPart
  113. //==========================================================
  114.  
  115. //----------------------------------------------------------
  116. //    CBeeperPart::CBeeperPart
  117. //----------------------------------------------------------
  118.  
  119. CBeeperPart::CBeeperPart(ODPart* odPart) :
  120.     FW_CPart(odPart, CBeeperPart::kPartKind),
  121.     fAction(NULL)
  122. {
  123. }
  124.  
  125. //----------------------------------------------------------
  126. //    CBeeperPart::~CBeeperPart
  127. //----------------------------------------------------------
  128.  
  129. CBeeperPart::~CBeeperPart()
  130. {
  131.     delete fAction;
  132. }
  133.  
  134. //----------------------------------------------------------
  135. //    CBeeperPart::Initialize
  136. //----------------------------------------------------------
  137.  
  138. void CBeeperPart::Initialize(Environment* ev)
  139. {
  140.     FW_CPart::Initialize(ev);
  141.     
  142.     // ----- Register our Presentation
  143.     CBeeperSelection *selection = 
  144.                             new CBeeperSelection(ev, this);
  145.     RegisterPresentation(ev, kODFBeeperPresentation, 
  146.                             TRUE, selection);
  147. }
  148.  
  149. //----------------------------------------------------------
  150. //    CBeeperPart::NewFrame
  151. //----------------------------------------------------------
  152.  
  153. FW_CFrame* CBeeperPart::NewFrame(Environment* ev,
  154.                              ODFrame* frame,
  155.                              FW_CPresentation* presentation,
  156.                              FW_Boolean storage)
  157. {
  158.     return new CBeeperFrame(ev, frame, presentation, this);
  159. }
  160.  
  161. //----------------------------------------------------------
  162. // CBeeperPart::InternalizeContent
  163. //----------------------------------------------------------
  164.  
  165. void CBeeperPart::InternalizeContent(Environment *ev, 
  166.                                 ODStorageUnit* storage, 
  167.                                 FW_CCloneInfo* cloneInfo)
  168. {
  169.     FW_ASSERT(fAction == NULL);
  170.     
  171.     if (CScriptAction::IsInStorage(ev, storage))
  172.         fAction = new CScriptAction();
  173.     else if (CSoundAction::IsInStorage(ev, storage))
  174.         fAction = new CSoundAction();
  175.     
  176.     if (fAction != NULL)
  177.         fAction->Internalize(ev, storage);
  178. }
  179.  
  180. //----------------------------------------------------------
  181. // CBeeperPart::ExternalizeContent
  182. //----------------------------------------------------------
  183. void CBeeperPart::ExternalizeContent(Environment *ev, 
  184.                                 ODStorageUnit* storage, 
  185.                                 FW_CCloneInfo* cloneInfo)
  186. {
  187.     // If any kind of property content exists...
  188.     if (storage->Exists(ev, kODPropContents, kODNULL, 0))
  189.     {
  190.         storage->Focus(ev, kODPropContents, 
  191.                     kODPosUndefined, kODNULL, 0, kODPosAll);
  192.         storage->Remove(ev);
  193.     }
  194.     storage->AddProperty(ev, kODPropContents);
  195.     if (fAction != NULL)
  196.         fAction->Externalize(ev, storage);
  197. }
  198.  
  199. //----------------------------------------------------------
  200. // CBeeperPart::DoAction
  201. //----------------------------------------------------------
  202. void CBeeperPart::DoAction()
  203. {
  204.     if (fAction != NULL)
  205.         fAction->DoIt();
  206. }
  207.  
  208. //------------------------------------------------------------------------------
  209. //    CBeeperPart::SetAction
  210. //------------------------------------------------------------------------------
  211.  
  212. void CBeeperPart::SetAction(CAction *action)
  213. {
  214.     if (action!=NULL && action!=fAction)
  215.     {
  216.         delete fAction;
  217.         fAction = action;
  218.     }
  219. }
  220.  
  221. //==========================================================
  222. //    class CBeeperFrame
  223. //==========================================================
  224.  
  225. //----------------------------------------------------------
  226. //    CBeeperFrame::CBeeperFrame
  227. //----------------------------------------------------------
  228.  
  229. CBeeperFrame::CBeeperFrame(Environment* ev, 
  230.                     ODFrame* frame, 
  231.                     FW_CPresentation* presentation, 
  232.                     CBeeperPart* part) :
  233.     FW_CFrame(ev, frame, presentation, part),
  234.     fBeeperPart(part),
  235.     fBeeper(NULL),
  236.     fButtonId(0),
  237.     fConnection(this),
  238.     fButtonNotificationToken(0)
  239. {
  240.     fConnection.Connect();
  241.     this->AddToFocusSet(ev,part->GetClipboardFocusToken(ev));
  242.     SetDroppable(ev, TRUE);
  243. }
  244.  
  245. //----------------------------------------------------------
  246. //    CBeeperFrame::~CBeeperFrame
  247. //----------------------------------------------------------
  248.  
  249. CBeeperFrame::~CBeeperFrame()
  250. {
  251.     FW_CInterest interest(fBeeper, fButtonNotificationToken);
  252.     fConnection.RemoveInterest(interest);
  253. }
  254.  
  255. //----------------------------------------------------------
  256. //    CBeeperFrame::CreateGadgetLayout
  257. //----------------------------------------------------------
  258.  
  259. void CBeeperFrame::CreateGadgetLayout(Environment* ev, 
  260.                         FW_CGadgetInitializer& initializer)
  261. {
  262.     FW_CDynamicString label("Beep");
  263.     
  264.     FW_CRect frameRect;
  265.     this->GetFrameShapeBounds(ev, frameRect);
  266.  
  267.     fBeeper = FW_NEW(FW_CPushButton, 
  268.             (ev, initializer, this, fButtonId, 
  269.             frameRect[FW_kTopLeft], frameRect[FW_kBotRight],
  270.             label));
  271.     fBeeper->SetDefault(ev, false);
  272.  
  273.     fButtonNotificationToken = 
  274.             fBeeper->GetButtonPressedNotificationToken(ev);
  275.     FW_CInterest interest(fBeeper, fButtonNotificationToken);
  276.     fConnection.AddInterest(interest);
  277. }
  278.  
  279. //----------------------------------------------------------
  280. //    CBeeperFrame::CanAcceptDrop
  281. //----------------------------------------------------------
  282.  
  283. ODDragResult CBeeperFrame::CanAcceptDrop(Environment* ev, 
  284.                             ODDragItemIterator* dragInfo)
  285. {
  286.     ODDragResult acceptDrop = 
  287.                 FW_CFrame::CanAcceptDrop(ev, dragInfo);
  288.  
  289.     if (!acceptDrop)
  290.     {
  291.         for (ODStorageUnit *dragSU = dragInfo->First(ev); 
  292.                             dragSU != NULL; 
  293.                             dragSU = dragInfo->Next(ev))
  294.         {
  295.             if (CSoundAction::IsInStorage(ev, dragSU))
  296.                 return TRUE;
  297.             if (CScriptAction::IsInStorage(ev, dragSU))
  298.                 return TRUE;
  299.         }
  300.     }
  301.  
  302.     return acceptDrop;
  303. }
  304.  
  305. //----------------------------------------------------------
  306. //    CBeeperFrame::Draw
  307. //----------------------------------------------------------
  308.  
  309. void CBeeperFrame::Draw(Environment* ev, 
  310.                         ODFacet* facet, 
  311.                         ODShape* invalidShape)
  312. {
  313.     FW_CFacetContext fc(ev, facet, invalidShape);
  314.     
  315.     // Just erase and assume gadgets will draw
  316.     FW_CRect invalidRect;
  317.     fc.GetClipRect(invalidRect);
  318.     FW_CRectShape::RenderRect(fc, invalidRect, 
  319.                             FW_kFill, FW_kWhiteEraseInk);
  320. }
  321.  
  322. //----------------------------------------------------------
  323. //    CBeeperFrame::HandleNotification
  324. //----------------------------------------------------------
  325.  
  326. void CBeeperFrame::HandleNotification(
  327.                     const FW_CNotification& notification)
  328. {
  329.     const FW_CButtonPressedNotification& buttonPressed =
  330.         (FW_CButtonPressedNotification&) notification;
  331.     
  332.     if (buttonPressed.GetButtonId() == fButtonId)
  333.     {
  334.         fBeeperPart->DoAction();
  335.     }
  336. }
  337.  
  338. //----------------------------------------------------------
  339. //    CBeeperFrame::FrameShapeChanged
  340. //----------------------------------------------------------
  341.  
  342. void CBeeperFrame::FrameShapeChanged(Environment* ev)
  343. {
  344.     FW_CFrame::FrameShapeChanged(ev);
  345.  
  346.     // Resize the Beeper to fit the new frame size
  347.     FW_CRect frameRect;
  348.     this->GetFrameShapeBounds(ev, frameRect);
  349.     fBeeper->SetSize(ev, frameRect.BotRight());
  350.  
  351.     // Redraw the entire frame
  352.     this->Invalidate(ev);
  353. }
  354.